<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class privateController extends CI_Controller {

 function __construct()
 {
     
   parent::__construct();
        $this->load->model('Pet');
        $this->load->model('Utente');
        $this->load->model('Service');
        $this->load->model('Address');
        $this->load->model('Role');
        $this->load->library('session');
        $this->load->helper('url');
   
 }
 

 function index()
 {
   if($this->session->userdata('logged_in'))
   {
     $session_data=$this->session->userdata('logged_in');
      $perm=$session_data['permessi'];
      $role=$this->Role->getRole($perm);
      echo $role;
      switch($role){
          
          case "admin" :  redirect('profilo/petsitter/'.$session_data['id'], 'refresh');
              break;
          case "petsitter" :  
              $url = 'profilo/petsitter/'.$session_data['id']."/";
              redirect($url, 'refresh');
              break; 
          case "petowner" :   redirect('profilo/petowner/'.$session_data['id'], 'refresh');
              break;
        }
      
   }
   else
   {
     //If no session, redirect to login page
     redirect('welcome/login()', 'refresh');
   }
 }

 function logout()
 {
   $this->session->unset_userdata('logged_in');
   session_destroy();
   redirect('welcome', 'refresh');
 }

}

?>